package com.ygq.xiaodi.controller;

import com.ygq.xiaodi.domain.User;
import com.ygq.xiaodi.service.UserService;
import com.ygq.xiaodi.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/pub/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录接口
     * @param user
     * @return
     */
    @PostMapping("login")
    public JsonData login(@RequestBody User user){
        System.out.println(user.toString());
        String token = userService.login(user.getUserName(), user.getPwd());
        return token != null ? JsonData.buildSuccess(token) : JsonData.buildError("账号密码错误");
    }

    /**
     * 列出全部用户
     * @return
     */
    @GetMapping("list")
    public JsonData listUser(){
        return JsonData.buildSuccess(userService.listUser());
    }


}
